var fs = require('fs');
var path = require('path');
var request = require('request');
var file = path.join(__dirname, 'url.txt');
// var file = path.join(__dirname, 'urlxx.txt');

function getUrl() {
	return new Promise(function(fullfil, reject) {
		fs.readFile(file, 'utf8', function(err, res) {
			if (err) reject(err);
			// else fullfil(res);
			else fullfil('http://haha.foo.bar.com'); // err
		});
	});
}

function makeRequest(url) {
	return new Promise(function(fullfil, reject) {
		request(url, function(err, res, body) {
			if (err) reject(err);
			fullfil(body);
		});
	});
}

// chain this
getUrl()

.then(function(url) {
	console.log('url=' + url);
	return makeRequest(url);
}, function(err) {
	console.log('getUrl err:' + err);
})

.then(function(body) {
	console.log(body.substring(0, 10));
}, function(err) {
	console.log('makeRequest err:' + err);
	// 后续步骤
})